package lighting;

import com.alibaba.fastjson.JSONObject;
import top.codedance.iotp.common.util.HexCodec;
import top.codedance.iotp.iot.sdk.StandandService;
import top.codedance.iotp.iot.sdk.po.sync.ComClientParam;
import top.codedance.iotp.iot.sdk.po.sync.ExecComParam;
import top.codedance.iotp.serialPortSDK.EnterpriseDeviceFactory;
import top.codedance.iotp.serialPortSDK.command.Seekway418XCommand;
import top.codedance.iotp.serialPortSDK.entity.seekway418x.Seekway418XInteger;
import top.codedance.iotp.serialPortSDK.enums.SeekWayBrightnessEnum;
import top.codedance.iotp.serialPortSDK.enums.SeekwayModeEnum;
import org.junit.Test;

public class Seekway418X {
    /**
     * 查询模式
     */
    @Test
    public void queryMode() {
        StandandService standandService = new StandandService("http://127.0.0.1:10012");
        ExecComParam execComParam = new ExecComParam();
        execComParam.setDeviceId("d1");
        execComParam.setUsername("u1");
        execComParam.setPassword("u1");
        ComClientParam comClientParam = new ComClientParam();
        comClientParam.setId(6);
        top.codedance.iotp.serialPortSDK.device.lighting.Seekway418X seekway418X = EnterpriseDeviceFactory.getSeekway418X();
        comClientParam.setCommand(new HexCodec().toBytes(Seekway418XCommand.MODE));
        execComParam.setClient(comClientParam);
        JSONObject jsonObject = standandService.execCom(execComParam);
        seekway418X.parse(jsonObject.getJSONObject("data").getString("context"));
        System.out.println(seekway418X.sresult);
    }


    /**
     * 更改模式
     */
    @Test
    public void modifyMode() {
        String command = Seekway418XCommand.changeModeCommand(SeekwayModeEnum.PATTERN, new Seekway418XInteger(10), null);
        StandandService standandService = new StandandService("http://127.0.0.1:10012");
        ExecComParam execComParam = new ExecComParam();
        execComParam.setDeviceId("d1");
        execComParam.setUsername("u1");
        execComParam.setPassword("u1");
        ComClientParam comClientParam = new ComClientParam();
        comClientParam.setId(6);
        top.codedance.iotp.serialPortSDK.device.lighting.Seekway418X seekway418X = EnterpriseDeviceFactory.getSeekway418X();
        comClientParam.setCommand(new HexCodec().toBytes(command));
        execComParam.setClient(comClientParam);
        JSONObject jsonObject = standandService.execCom(execComParam);
        seekway418X.parse(jsonObject.getJSONObject("data").getString("context"));
        System.out.println(seekway418X.sresult);
    }

    /**
     * 查询速度
     */
    @Test
    public void querySpeed() {
        StandandService standandService = new StandandService("http://127.0.0.1:10012");
        ExecComParam execComParam = new ExecComParam();
        execComParam.setDeviceId("d1");
        execComParam.setUsername("u1");
        execComParam.setPassword("u1");
        ComClientParam comClientParam = new ComClientParam();
        comClientParam.setId(6);
        top.codedance.iotp.serialPortSDK.device.lighting.Seekway418X seekway418X = EnterpriseDeviceFactory.getSeekway418X();
        comClientParam.setCommand(new HexCodec().toBytes(Seekway418XCommand.SPEED));
        execComParam.setClient(comClientParam);
        JSONObject jsonObject = standandService.execCom(execComParam);
        seekway418X.parse(jsonObject.getJSONObject("data").getString("context"));
        System.out.println(seekway418X.sresult);
    }

    /**
     * 更改速度
     */
    @Test
    public void modifySpeed() {
        String command = Seekway418XCommand.changeSpeedCommand(50);
        StandandService standandService = new StandandService("http://127.0.0.1:10012");
        ExecComParam execComParam = new ExecComParam();
        execComParam.setDeviceId("d1");
        execComParam.setUsername("u1");
        execComParam.setPassword("u1");
        ComClientParam comClientParam = new ComClientParam();
        comClientParam.setId(6);
        top.codedance.iotp.serialPortSDK.device.lighting.Seekway418X seekway418X = EnterpriseDeviceFactory.getSeekway418X();
        comClientParam.setCommand(new HexCodec().toBytes(command));
        execComParam.setClient(comClientParam);
        JSONObject jsonObject = standandService.execCom(execComParam);
        seekway418X.parse(jsonObject.getJSONObject("data").getString("context"));
        System.out.println(seekway418X.sresult);
    }

    /**
     * 查询亮度
     */
    @Test
    public void queryBrightness() {
        StandandService standandService = new StandandService("http://127.0.0.1:10012");
        ExecComParam execComParam = new ExecComParam();
        execComParam.setDeviceId("d1");
        execComParam.setUsername("u1");
        execComParam.setPassword("u1");
        ComClientParam comClientParam = new ComClientParam();
        comClientParam.setId(6);
        top.codedance.iotp.serialPortSDK.device.lighting.Seekway418X seekway418X = EnterpriseDeviceFactory.getSeekway418X();
        comClientParam.setCommand(new HexCodec().toBytes(Seekway418XCommand.BRIGHTNESS));
        execComParam.setClient(comClientParam);
        JSONObject jsonObject = standandService.execCom(execComParam);
        seekway418X.parse(jsonObject.getJSONObject("data").getString("context"));
        System.out.println(seekway418X.sresult);
    }

    /**
     * 更改亮度
     */
    @Test
    public void midifyBrightness() {
        String command = Seekway418XCommand.changeBrightnessCommand(SeekWayBrightnessEnum.BLACK);
        StandandService standandService = new StandandService("http://127.0.0.1:10012");
        ExecComParam execComParam = new ExecComParam();
        execComParam.setDeviceId("d1");
        execComParam.setUsername("u1");
        execComParam.setPassword("u1");
        ComClientParam comClientParam = new ComClientParam();
        comClientParam.setId(6);
        top.codedance.iotp.serialPortSDK.device.lighting.Seekway418X seekway418X = EnterpriseDeviceFactory.getSeekway418X();
        comClientParam.setCommand(new HexCodec().toBytes(command));
        execComParam.setClient(comClientParam);
        JSONObject jsonObject = standandService.execCom(execComParam);
        seekway418X.parse(jsonObject.getJSONObject("data").getString("context"));
        System.out.println(seekway418X.sresult);
    }
}
